package com.ogilvy.audi.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ogilvy.audi.bean.Album;
import com.ogilvy.audi.dao.AlbumDao;
import com.ogilvy.audi.service.AlbumService;
import com.ogilvy.audi.util.AudiConstants;
import com.ogilvy.frame.service.BaseServiceImpl;

@Service
public class AlbumServiceImpl extends BaseServiceImpl implements AlbumService{
	@Autowired
	 AlbumDao albumDao;
	public List<Album> query(){
		return null;
	}
	public List<Album> query(int pageNo, int pageSize,Map<String,Object> condition){
		return albumDao.selectAll(pageNo, pageSize, condition);
	}
	public List<Album> query(Map<String,Object> condition){
		return albumDao.selectAll(condition);
	}
	public Album get(Integer albumId){
		return albumDao.get(albumId);
	}
	public List<String> getPicList(Integer albumId){
		Album album = get(albumId);
		String picDir = AudiConstants.ROOT_ALBUM_URL;
		picDir += album.getUrlAddress();
		//File f = new File("E:\\eclipseWorkSpace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\AudiProject\\album\\defautblaum2");
		File f = new File(picDir);
		
		String[] piclist = f.list();
		List<String> pList = new ArrayList();
		
		System.out.println("____________________________________________________图片路径："+picDir);
		System.out.println("____________________________________________________图片路径："+f);
		System.out.println("____________________________________________________图片列表："+piclist);
		
		
		for(int i=0;i<piclist.length;i++){
			pList.add(piclist[i]);
			if(i>4){break;}
		}
		return pList;
		
		
		
		
	}
	public Album add(Album album){
		Album album_ = albumDao.save(album);
		return album!=null?album:null;
	}
	public boolean del(Integer albumId){
		Album album_ = albumDao.deleteById(albumId);
		return album_!=null?true:false;
	}
	
}
